1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #define red 1 #define yellow 2 #define green 3 void setup() { pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); } void loop() { trafficLights(red); trafficLights(yellow); trafficLights(green); } void trafficLights(int light) { switch(light){ case 1: digitalWrite(2,HIGH); digitalWrite(3,LOW); digitalWrite(4,LOW); delay(4000); case 2: for(int i=0;i<7;i++) { digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(4,HIGH); delay(200); digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(4,LOW); delay(200); } case 3: digitalWrite(2,LOW); digitalWrite(3,HIGH); digitalWrite(4,LOW); delay(4000); break; } }
|